package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.evaluate.SubmitEvaluateItemBean;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;
import com.net.wanjian.networkhospitalmanager.view.LRatingBar;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by lidongcai on 17/7/19.
 * Email:  lidongcaiocc@163.com
 */

public class SimpleEvaluateRatingAdapter extends RecyclerBaseAdapter<SubmitEvaluateItemBean.EvaluationItemListBean, SimpleEvaluateRatingAdapter.ViewHolder> {

    private HashMap<Integer,Integer> score;
    private int evaluated;

    public SimpleEvaluateRatingAdapter(Context context,int evaluated) {
        super(context);
        score = new HashMap<>();
        this.evaluated = evaluated;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_simple_evaluate_item, parent, false);
        AutoUtils.auto(view);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, SubmitEvaluateItemBean.EvaluationItemListBean item, final int position) {
        //默认选中的值
        score.put(position,item.getEvaluationItemValueResult());

        holder.itemSimpleEvaluateItemTextTv.setText(URLDecoderUtil.getDecoder(item.getEvaluationItemName())+"：");

        LRatingBar ratingBar = holder.itemSimpleEvaluateItemRatingbar;
        if (evaluated == 0){
            ratingBar.setClickable(true);
        }else {
            ratingBar.setClickable(false);
        }

        Log.e("ratingsetsartt", "onBindViewHolder: "+item.getEvaluationItemValueResult());
        ratingBar.setStar(item.getEvaluationItemValueResult());
        ratingBar.setOnRatingChangeListener(new LRatingBar.OnRatingChangeListener() {
            @Override
            public void onRatingChange(float ratingCount) {
                score.put(position, (int) ratingCount);
            }
        });


    }

    public HashMap<Integer, Integer> getScore() {
        return score;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_simple_evaluate_item_text_tv)
        TextView itemSimpleEvaluateItemTextTv;
        @BindView(R.id.item_simple_evaluate_item_ratingbar)
        LRatingBar itemSimpleEvaluateItemRatingbar;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
